package com.sx.utils;

import com.alibaba.fastjson.JSON;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.ColumnListHandler;
import org.apache.commons.dbutils.handlers.MapListHandler;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;

public class echatTools
{
    public static String  playerInfo() {
      Connection conn = DBUtils.getConnection();
        String sql="SELECT category FROM `game` GROUP BY category";
        QueryRunner queryRunner=new QueryRunner();
        List list= null;
        try {
            list = queryRunner.execute(conn, sql,new ColumnListHandler());
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        String result= JSON.toJSONString(list);
        result = result.replace("[[", "[");
        result = result.replace("]]", "]");
      System.out.println(result);
        return result;
    }

    public static String  playerInfoValue() {
        Connection conn = DBUtils.getConnection();
        String sql="SELECT count(*) FROM `game` GROUP BY category";
        QueryRunner queryRunner=new QueryRunner();
        List list= null;
        try {
            list = queryRunner.execute(conn, sql,new ColumnListHandler());
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        assert list != null;
        String result = Arrays.toString(list.toArray());
        result = result.replace("[[", "[");
        result = result.replace("]]", "]");
      System.out.println(result);
        return result;
    }
}
